﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.PortableExecutable;
using System.Text;
using System.Threading.Tasks;

namespace ManageData
{
    internal class 删除关系
    {
        void MyMethod()
        {
            using (var db = new BasicDbContext())
            {
                var mainEntity = db.MainEntities.First();

                mainEntity.SubEntities.RemoveAt(0);
                mainEntity.SubEntities.First().MainEntity = null;
                mainEntity.SubEntities.First().MainEntityId = null;

                db.Remove(mainEntity);
                db.SaveChanges();
            }

        }
    }
}
